#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int testIsGameOver(struct gameState *state) {
	int i;
	int j;

	//if stack of Province cards is empty, the game ends
	if (state->supplyCount[province] == 0)
	{
		return 1;
	}

	//if three supply pile are at 0, the game ends
	j = 0;
	for (i = 0; i < 25; i++)
	{
		if (state->supplyCount[i] == 0)
		{
			j++;
		}
	}
	if ( j >= 3)
	{
		return 1;
	}

	return 0;
}

void test()
{
	struct gameState g;
	struct gameState * game = &g;
	memset(game, 0, sizeof(struct gameState));
	
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
		sea_hag, tribute, smithy};
	initializeGame(4, k, 2, game);
		
	game->supplyCount[province] = 0;
	
	if (testIsGameOver(game) == 1)
		printf("isGameOver(): PASS when test stack of province cards is empty\n");
	else
		printf("isGameOver(): FAIL when test stack of province cards is empty\n");
	
	initializeGame(4, k, 2, game);
	
	if (testIsGameOver(game) == 0)
		printf("isGameOver(): PASS when test initialized game\n");
	else
		printf("isGameOver(): FAIL when test initialized game\n");

	game->supplyCount[0] = 0;
	game->supplyCount[12] = 0;
	game->supplyCount[24] = 0;
	
	if (testIsGameOver(game) == 1)
		printf("isGameOver(): PASS when test three supply piles are empty\n");
	else
		printf("isGameOver(): FAIL when test three supply piles are empty\n");	
}

int main(int argc, char *argv[])
{
	test();
	return 0;
}
